package cn.silver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 启动程序
 *
 * @author Lion Li
 */
@Slf4j
@SpringBootApplication
public class SilverApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SilverApplication.class);
    }

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(SilverApplication.class, args);
        application.setApplicationStartup(new BufferingApplicationStartup(2048));
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        log.info("----------------------------------------------------------\n - Local: \t\t\thttp://localhost:{}/                  \n - External: \t\thttp://{}:{}/                \n - SpringDoc文档: \thttp://{}:{}/doc.html      \n - ----------------------------------------------------------", port, ip, port, ip, port);
//        log.info("-----------------------------------------------------------");
//        log.info("Local: \t\t\thttp://localhost:{}", port);
//        log.info("External: \t\thttp://{}:{}", ip, port);
//        log.info("SpringDoc文档: \thttp://{}:{}/doc.html", ip, port);
//        log.info("-----------------------------------------------------------");
    }

}
